<?php

namespace Acme\CommonBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Acme\CommonBundle\Entity\ConstArea
 *
 * @ORM\Table(name="const_area")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks()
 */
class ConstArea
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
     */
    private $name;

    /**
     * @var integer $pid
     *
     * @ORM\Column(name="pid", type="integer", nullable=true)
     */
    private $pid;

    /**
     * @var integer $level
     *
     * @ORM\Column(name="level", type="integer", nullable=true)
     */
    private $level;
    
    /**
     * @var string $flag
     *
     * @ORM\Column(name="flag", type="string", length=1, nullable=true)
     */
    private $flag;
    
    /**
     * Inverse Side
     * @ORM\OneToMany(targetEntity="\Acme\CommonBundle\Entity\ConstUniversity", mappedBy="areaInfo")
     */
    protected $universities;
    
    /**
     * @ORM\OneToMany(targetEntity="ConstArea", mappedBy="parent")
     */
    protected $children;
    
    /**
     * self-reference
     * @ORM\ManyToOne(targetEntity="ConstArea", inversedBy="children")
     * @ORM\JoinColumn(name="pid", referencedColumnName="id")
     */
    protected $parent;
    
    public function __construct()
    {
    	$this->universities = new ArrayCollection();
    	$this->children = new ArrayCollection();
    }
    
    private $fullName;

    public function getFullName()
    {
    	if ($this->level != 0) {
    		return $this->getParent()->getName() . $this->name;
    	} else {
    		return $this->name;
    	}
    }


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set pid
     *
     * @param integer $pid
     */
    public function setPid($pid)
    {
        $this->pid = $pid;
    }

    /**
     * Get pid
     *
     * @return integer 
     */
    public function getPid()
    {
        return $this->pid;
    }

    /**
     * Set level
     *
     * @param integer $level
     */
    public function setLevel($level)
    {
        $this->level = $level;
    }

    /**
     * Get level
     *
     * @return integer 
     */
    public function getLevel()
    {
        return $this->level;
    }
    
    /**
     * Set flag
     *
     * @param string $flag
     * 
     * @ORM\prePersist
     */
    public function setFlag($flag = 0)
    {
    	$this->flag = $flag;
    }
    
    /**
     * Get flag
     *
     * @return string
     */
    public function getFlag()
    {
    	return $this->flag;
    }

    /**
     * Add universities
     *
     * @param Acme\CommonBundle\Entity\ConstUniversity $universities
     */
    public function addConstUniversity(\Acme\CommonBundle\Entity\ConstUniversity $universities)
    {
        $this->universities[] = $universities;
    }

    /**
     * Get universities
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getUniversities()
    {
        return $this->universities;
    }

    /**
     * Add children
     *
     * @param Acme\CommonBundle\Entity\ConstArea $children
     */
    public function addConstArea(\Acme\CommonBundle\Entity\ConstArea $children)
    {
        $this->children[] = $children;
    }

    /**
     * Get children
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getChildren()
    {
        return $this->children;
    }

    /**
     * Set parent
     *
     * @param Acme\CommonBundle\Entity\ConstArea $parent
     */
    public function setParent(\Acme\CommonBundle\Entity\ConstArea $parent)
    {
        $this->parent = $parent;
    }

    /**
     * Get parent
     *
     * @return Acme\CommonBundle\Entity\ConstArea 
     */
    public function getParent()
    {
        return $this->parent;
    }
}